﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace QuangMobile
{
    public partial class UCNavigate : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadDanhMuc("sp", rptSanPham);
            LoadDanhMuc("pk", rptPhuKien);
            LoadDanhMuc("dv", rptDichVu);
            LoadPromotion();
            LoadYahooList();
        }

        private void LoadPromotion()
        {
            string sql = "SELECT * FROM dbo.tblWebQuangCao WHERE IsUse = 1";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ltrImage.Text += "<img src='" + dt.Rows[i]["AttachFile"] + "' alt='' />";
            }
        }

        private void LoadDanhMuc(string MaDM, Repeater rpt)
        {
            string sql = "Select * from tblWebDanhMuc where MaDM = @MaDM";
            List<SqlParameter> arParams = new List<SqlParameter>();
            arParams.Add(SqlHelper.CreateParameterObject("@MaDM", SqlDbType.NVarChar, ParameterDirection.Input, MaDM));
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, arParams);
            rpt.DataSource = dt;
            rpt.DataBind();
        }

        private void LoadYahooList()
        {
            string sql = "Select * from tblWebDanhMuc where MaDM = 'yahoo'";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ltrYahoo.Text += "<a href='ymsgr:sendim?" + dt.Rows[i]["TenDM"] + "'><img width='125' height='25' border='0' src='http://opi.yahoo.com/online?u=" + dt.Rows[i]["TenDM"] + "&m=g&t=2' style='border: 0px none;'></a><br /><br />";
            }
        }
    }
}